/**处理校区上课时间**/
var setCampusTime = function(timelist) {
	if(timelist.length <= 0) {
		config.weekTimeList = [];
		setDayTime("07:00", "21:00");
		return;
	}

	config.weekTimeList = timelist.map(function(row) {
		let endIndex = row.startTime.lastIndexOf(":");
		return {
			startTime: row.startTime.substring(0, endIndex),
			endTime: row.endTime.substring(0, endIndex),
			weekMode: row.weekMode
		}
	})

	let mintemplist = config.weekTimeList.sort(function(x, y) {

		return x.startTime > y.startTime ? 1 : -1;
	});
	let maxtemplist = config.weekTimeList.sort(function(x, y) {

		return x.endTime < y.endTime ? 1 : -1;
	});
	let sTime = mintemplist[0].startTime || "07:00";
	let eTime = maxtemplist[0].endTime || "21:00";
	setDayTime(sTime, eTime)

}

/**一天的上课时间与结束时间**/
var setDayTime = function(dayStartTime, dayEndTime) {

	let startHour = dayStartTime.split(":")[0];
	let endHour = dayEndTime.split(":")[0];
	startHour = Number(startHour.at(0)) == 0 ? Number(startHour.at(1)) : Number(startHour);
	endHour = Number(endHour.at(0)) == 0 ? Number(endHour.at(1)) : Number(endHour);

	config.campusTime.maxEndTime = endHour + 1;
	config.campusTime.minStartTime = startHour;
	config.timtlist = [];

	for(let i = config.campusTime.minStartTime; i < config.campusTime.maxEndTime; i++) {
		let hour = i < 10 ? ('0' + i + ":00") : (i + ":00");
		config.timtlist.push({
			time: hour
		})
	}
}

export default setCampusTime;

